#!/usr/bin/perl -w
use strict;

my $fileName = 'urls-log.txt';

# Read the file...
open IN, '<', $fileName;
my @lines = <IN>;
close IN;

my %counts = ();
my %domains = ();

foreach my $line (@lines)
{
	my @items = split(/ /,$line);
	my $url = $items[-1];
	if( $counts{$url} )
	{
		$counts{$url} += 1;
	}
	else
	{
		$counts{$url} = 1;
	}
	
	if($url =~ /([^:]*:\/\/)?([^\/]+\.[^\/]+)/g) {
		# print $2, "\n";
		if($domains{$2})
		{
			$domains{$2} += 1;
		}
		else
		{
			$domains{$2} = 1
		}
	}
	else 
	{ 
		print 'ca not find domain in ', $url, "\n"; 
	}
}

print "\ndomains counts:\n";
foreach (keys %domains)
{
	print $domains{$_}, ' ', $_, "\n";
}
print "\n\n";

print "URLs counts:\n";
foreach (keys %counts)
{
	print $counts{$_}, ' ', $_;
}